package com.ruoyi.dream.controller;

import java.util.List;

import com.ruoyi.dream.service.IEduCourseService;
import com.ruoyi.dream.service.impl.EduMajorServiceImpl;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import com.ruoyi.dream.service.IEduProgramService;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.dream.domain.EduProgram;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 培养方案管理Controller
 * 
 * @author ruoyi
 * @date 2025-05-07
 */
@Controller
@RequestMapping("/dream/program")
public class EduProgramController extends BaseController
{
    private String prefix = "dream/program";

    @Autowired
    private IEduProgramService eduProgramService;

    @Autowired
    private IEduCourseService eduCourseService;
    @Autowired
    private EduMajorServiceImpl eduMajorServiceImpl;

    @RequiresPermissions("dream:program:view")
    @GetMapping()
    public String program()
    {
        return prefix + "/program";
    }

    /**
     * 查询培养方案管理列表
     */
    @RequiresPermissions("dream:program:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(EduProgram eduProgram)
    {
        startPage();
        List<EduProgram> list = eduProgramService.selectEduProgramList(eduProgram);
        return getDataTable(list);
    }

    /**
     * 导出培养方案管理列表
     */
    @RequiresPermissions("dream:program:export")
    @Log(title = "培养方案管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(EduProgram eduProgram)
    {
        List<EduProgram> list = eduProgramService.selectEduProgramList(eduProgram);
        ExcelUtil<EduProgram> util = new ExcelUtil<EduProgram>(EduProgram.class);
        return util.exportExcel(list, "培养方案管理数据");
    }

    /**
     * 新增培养方案管理
     */
    @RequiresPermissions("dream:program:add")
    @GetMapping("/add")
    public String add(ModelMap mmap)
    {
        mmap.put("eduMajors", eduMajorServiceImpl.selectEduMajorList(null));
        return prefix + "/add";
    }

    /**
     * 新增保存培养方案管理
     */
    @RequiresPermissions("dream:program:add")
    @Log(title = "培养方案管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(EduProgram eduProgram)
    {
        return toAjax(eduProgramService.insertEduProgram(eduProgram));
    }

    /**
     * 修改培养方案管理
     */
    @RequiresPermissions("dream:program:edit")
    @GetMapping("/edit/{programId}")
    public String edit(@PathVariable("programId") Long programId, ModelMap mmap)
    {
        EduProgram eduProgram = eduProgramService.selectEduProgramByProgramId(programId);
        mmap.put("eduProgram", eduProgram);
        mmap.put("eduMajors", eduMajorServiceImpl.selectEduMajorList(null));
        return prefix + "/edit";
    }

    /**
     * 修改保存培养方案管理
     */
    @RequiresPermissions("dream:program:edit")
    @Log(title = "培养方案管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(EduProgram eduProgram)
    {
        return toAjax(eduProgramService.updateEduProgram(eduProgram));
    }

    /**
     * 删除培养方案管理
     */
    @RequiresPermissions("dream:program:remove")
    @Log(title = "培养方案管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(eduProgramService.deleteEduProgramByProgramIds(ids));
    }
}
